package com.situ.water_BE.controller;


import com.situ.water_BE.pojo.BeComment;
import com.situ.water_BE.service.BeCommentService;
import com.situ.water_system.pojo.SyEmp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author Angel
 * @since 2020-12-01
 */
@RestController
@RequestMapping("/be-comment")
public class BeCommentController { //工单附加信息
    @Autowired
    private BeCommentService beCommentService;

    @GetMapping("/queryAll")
    public List<Map> queryAll(String orderNo) {
        return beCommentService.queryAllSQL(orderNo);
    }

    @PostMapping("/addBeComment")
    public List<Map> add(BeComment beComment) {
        int i = beCommentService.addBeComment(beComment);
        return beCommentService.queryAllSQL(beComment.getOrderNo());
    }
    @PutMapping("/updateBeComment")
    public List<Map> updateBeComment(BeComment beComment) {
        int i = beCommentService.updateBeComment(beComment);
        return beCommentService.queryAllSQL(beComment.getOrderNo());
    }
    @DeleteMapping("/deleteBeComment")
    public List<Map> deleteBeComment(BeComment beComment) {
        System.out.println(beComment);
        int i = beCommentService.deleteBeComment(beComment.getId());
        return beCommentService.queryAllSQL(beComment.getOrderNo());
    }

    /**
     * 根据编号获取业扩工单
     * @param orderNo
     * @return
     */
    @GetMapping("/queryByBeOrder")
    public Map queryByBeOrder(String orderNo){

        return beCommentService.queryByBeOrderSQL(orderNo);
    }
    @GetMapping("/queryListBeOrderUser")
    public List<Map> queryListBeOrderUser(String orderNo){
        return beCommentService.queryListBeOrderUserSQL(orderNo);
    }
    /**
     * 获取session
     * @param session
     * @return
     */
    @GetMapping("/getSession")
    public SyEmp getSession(HttpSession session) {
        SyEmp user = (SyEmp) session.getAttribute("user");
        SyEmp emp = new SyEmp();
        if (user == null) {
            emp.setId(10);
            session.setAttribute("user", emp);
        }
        user = (SyEmp) session.getAttribute("user");
        return user;
    }
}

